package rgbos.forum.persistance;

import java.util.Vector;

import rgbos.forum.domain.Post;
import rgbos.forum.domain.Topic;
import rgbos.forum.domain.User;

public class SQLFacade implements PersImpl {

	private SQLPost sqlPost_;
	private SQLTopic sqlTopic_;
	private SQLUser sqlUser_;
	private SQLUtil sqlUtil_;

	public SQLFacade(){
		sqlPost_ = new SQLPost();
		sqlTopic_= new SQLTopic();
		sqlUser_ = new SQLUser();
		sqlUtil_ = new SQLUtil();
	}
	public void connect() {
		sqlUtil_.connect();
	}
	@Override
	public boolean changePermission(String username, int value) {
		return sqlUser_.changePermission(username, value);
	}

	@Override
	public boolean checkAdmin(String username) {
		return sqlUser_.checkAdmin(username);
	}

	@Override
	public boolean checkExistUser(String username) {
		return sqlUser_.checkExistUser(username);
	}

	@Override
	public boolean checkModerator(String username) {
		return sqlUser_.checkModerator(username);
	}

	@Override
	public boolean deletePost(int postId) {
		return sqlPost_.deletePost(postId);
	}

	@Override
	public boolean deleteTopic(int topicId) {
		return sqlTopic_.deleteTopic(topicId);
	}

	@Override
	public boolean deleteUser(String username) {
		return sqlUser_.deleteUser(username);
	}

	@Override
	public Post getPostById(int postId) {
		return sqlPost_.getPostById(postId);
	}

	@Override
	public Vector<Post> getPosts() {
		return sqlPost_.getPosts();
	}

	@Override
	public Topic getTopicById(int topicId) {
		return sqlTopic_.getTopicById(topicId);
	}

	@Override
	public Vector<Topic> getTopics() {
		return sqlTopic_.getTopics();
	}

	@Override
	public Vector<User> getUsers() {
		return sqlUser_.getUsers();
	}
	@Override
	public Vector<String> getUsersName() {
		return sqlUser_.getUsersName();
	}

	@Override
	public boolean logIn(String userName, String pass) {
		return sqlUser_.logIn(userName, pass);
	}

	@Override
	public boolean modifyPost(Post post) {
		return sqlPost_.modifyPost(post);
	}

	@Override
	public boolean modifyPostBody(int postId, String title,String body) {
		return sqlPost_.modifyPostBody(postId,title,body);
	}

	@Override
	public boolean modifyTopic(Topic topic) {
		return sqlTopic_.modifyTopic(topic);
	}

	@Override
	public boolean modifyUserDetails(User user) {
		return sqlUser_.modifyUserDetails(user);
	}

	@Override
	public boolean registerNewUser(User newUser) {
		return sqlUser_.registerNewUser(newUser);
	}

	@Override
	public int saveNewPost(Post post, int topicId) {
		return sqlPost_.saveNewPost(post, topicId);
	}

	@Override
	public int saveNewTopic(Topic topic) {
		return sqlTopic_.saveNewTopic(topic);
	}

	@Override
	public boolean setAdmin(String username) {
		return sqlUser_.setAdmin(username);
	}

	@Override
	public boolean setModerator(String username) {
		return sqlUser_.setModerator(username);
	}
	public void addViewCount(int topicId){
		sqlTopic_.addViewCount(topicId);
	}
	@Override
	public void createNewTables() {
		sqlUtil_.createNewTables();
	}
	@Override
	public Vector<User> getOnlineUsers() {
		return sqlUser_.getOnlineUsers();
	}
	@Override
	public int getOnlineBit(String userName) {
		return sqlUser_.getOnlineBit(userName);
	}
	@Override
	public boolean setOnlineBit(String userName, int onlineBit) {
		return sqlUser_.setOnlineBit(userName, onlineBit);
	}
	@Override
	public User getUserByName(String username) {
		return sqlUser_.getUserByName(username);
	}
	@Override
	public void addCulumn(String columnName, String columnType) {
		sqlUtil_.addCulomn(columnName,columnType);
		
	}
	@Override
	public Vector<Post> getPostsByUser(String username) {
		return sqlPost_.getPostsByUser(username);
	}
	@Override
	public String getEmailByName(String userName) {
		return sqlUser_.getEmailByName(userName);
	}
	@Override
	public void closeConnection() {
		sqlUtil_.closeConnection();
	}
	@Override
	public int[] getHourStats() {
		return sqlUser_.getHourStats();
	}
	@Override
	public boolean incHour(int hour) {
		return sqlUser_.incHour(hour);
	}
	@Override
	public void createUsersHours() {
		sqlUtil_.createTableUserHour();
	}
	@Override
	public Topic getTopicByPost(int id) {		
		return sqlTopic_.getTopicByPost(id);
	}

}
